from sympy import Symbol, Piecewise, limit

if __name__ == '__main__':
    x = Symbol("x")

    f = Piecewise(
        (x - 1, x < 0),
        (0, x == 0),
        (x + 1, x > 0)
    )

    # 计算左极限的值
    left_limit = limit(f, x, 0, dir="-")
    print("left_limit = ", left_limit)

    # 计算右极限的值
    right_limit = limit(f, x, 0, dir="+")
    print("right_limit = ", right_limit)

    # value = f.subs(x, 0)
    # print("value = ", value)



